package com.example.mealplanner;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

public class MenuActivity extends Activity {

	ArrayList<ImageButton> iconList = new ArrayList<ImageButton>();
	Button searchButton;
	EditText searchField;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu);

		searchField = (EditText) findViewById(R.id.search_restaurant_name);
		searchButton = (Button) findViewById(R.id.search_button);
		
		groupIcon();
		for (ImageButton icon: iconList){
			final String description = icon.getContentDescription().toString();
			icon.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					String message = description + " selected";
					Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
				}
			});
		}
		
		
		searchButton.setOnClickListener(new View.OnClickListener() {
		
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String keyword = searchField.getText().toString();
				Toast.makeText(getApplicationContext(), "Search : " + keyword, Toast.LENGTH_SHORT).show();
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}

	public void groupIcon(){
		iconList.add((ImageButton) findViewById(R.id.imageButton1));
		iconList.add((ImageButton) findViewById(R.id.imageButton2));
		iconList.add((ImageButton) findViewById(R.id.imageButton3));
		iconList.add((ImageButton) findViewById(R.id.ImageButton4));
		iconList.add((ImageButton) findViewById(R.id.ImageButton5));
		iconList.add((ImageButton) findViewById(R.id.ImageButton6));
		iconList.add((ImageButton) findViewById(R.id.ImageButton7));
		iconList.add((ImageButton) findViewById(R.id.ImageButton8));
		iconList.add((ImageButton) findViewById(R.id.ImageButton9));
	}
}
